files.cpp (File I/O)
Source: src/modules/files.cpp
The files module handles the physical transfer of data bytes between the implant's memory and the host's disk. It is divided into two distinct functions: get_file (Download) and put_file (Upload).
Function: get_file
Reads a file from the host OS and returns it for exfiltration.
Function Signature
ModuleResult get_file(std::string file_path);
Logic & Behavior
- Handle Acquisition: Opens the file using
CreateFileWwithGENERIC_READpermissions andFILE_SHARE_READ(allowing other processes to read the file simultaneously). - Size Calculation: Uses
GetFileSizeExto determine the exact number of bytes to allocate for the buffer. - Reading: Reads the file contents into a
std::stringbuffer.
Return Values (ModuleResult)
data: The raw binary contents of the file.windows_error_code:ERROR_SUCCESS(0): File read successfully.- WinAPI Error: If the file is locked, doesn't exist, or access is denied, returns the relevant
GetLastError()code.
Function: put_file
Writes a stream of bytes from the implant to the host disk.
Function Signature
ModuleResult put_file(std::vector<uint8_t> file_contents, std::string file_path);
Logic & Behavior
- Handle Acquisition: Opens a handle using
CreateFileWwithGENERIC_WRITE, and adwShareModeof0(this prevents other processes from Read, Write, or Delete while we write our info) . - Creation Flags: Uses
CREATE_NEW.
- Note: This means the operation will fail if the file already exists. It does not overwrite by default to prevent accidental data destruction on the target.
- Locking: Uses
0for share mode, preventing other processes from accessing the file while it is being written.
Return Values (ModuleResult)
data: A status message (e.g., "File written successfully").windows_error_code:ERROR_SUCCESS(0): Write completed.ERROR_FILE_EXISTS(80): Common error if the target file already exists (due toCREATE_NEW).